package com.ym.controller;

import com.ym.pojo.Account;
import com.ym.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @version 1.0
 * 公众号：Java架构栈
 * @Author: 卓不凡
 */

@Controller  //标记是一个控制层
@RequestMapping("h")
public class HelloController {
    @RequestMapping("hello")
    public String hello(){
        System.out.println("hello 执行了");
        return "success";
    }

    @PostMapping("hello1")
    public String hello2(Account account){
        System.out.println(account.getId());
        System.out.println(account.getName());
        System.out.println(account.getMoney());
        return "success";
    }

    @GetMapping("hello2")
    public String hello2(int id,String name,Double money){
        System.out.println(id);
        System.out.println(name);
        System.out.println(money);
        return "success";
    }

    @RequestMapping(value = "test",method = RequestMethod.POST)
    @ResponseBody
    public String ajax(String username,int age){
        System.out.println(username);
        System.out.println(age);
        return "aaaaaaa";
    }

    @RequestMapping(value = "test2",method = RequestMethod.POST)
    @ResponseBody
    public String ajax2(@RequestBody User user){
        System.out.println(user.getName());
        System.out.println(user.getAge());
        return "aaaaaaa";
    }

    @PostMapping("test3")
    @ResponseBody   //响应的是json数据格式
    public User demo02(@RequestBody User user){   //@RequestBody  :contentType:applicaton/json;charset=UTF-8
        System.out.println(user);
        return user;
    }

}
